import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup} from "@angular/forms";

const data = [
  {
    url: 'assets/src/img/product1.png'
  },
  {
    url: 'assets/src/img/product2.png'
  }
];
const data1 = [
  {
    url: 'assets/src/img/product2.png'
  },
  {
    url: 'assets/src/img/product1.png'
  },
  {
    url: 'assets/src/img/product2.png'
  }

];

@Component({
  selector: 'app-suggestions',
  templateUrl: './suggestions.page.html',
  styleUrls: ['./suggestions.page.less'],
})
export class SuggestionsPage implements OnInit {

  constructor() { }

  ngOnInit() {
    this.buildForm();
  }

  registerForm: FormGroup;
  formData: any = {
    type: "complain",
    contact: "",
    description: "",
  };

  index = 0;
  onChange(item) {
    console.log('onChange', item);
  }

  onTabClick(item) {
    console.log('onTabClick', item);
  }

  myList = [{
    'type': "complain",
    'description': "LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障。",
    'contact': "",
    'images': data1.slice(0),
    'solve': true
  }, {
    'type': "complain",
    'description': "LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障。",
    'contact': "",
    'images': data1.slice(0),
    'solve': true
  }, {
    'type': "suggestion",
    'description': "LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障。",
    'contact': "",
    'images': data1.slice(0),
    'solve': false
  }, {
    'type': "suggestion",
    'description': "LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障，LAM系列（6级）三相异步电机出现故障。",
    'contact': "",
    'images': data1.slice(0),
    'solve': true
  }]

  buildForm(): void {
    this.registerForm = new FormGroup({
      type: new FormControl(this.formData.type, []),
      contact: new FormControl(this.formData.contact, []),
      description: new FormControl(this.formData.description, []),
    });

  }

  files = data.slice(0);
  multiple = false;
  des = "您好，您反映的问题已交给我们的维修部进行处理请耐心等待。";

  imageChange(params) {
    const { files, type, index } = params;
    this.files = files;
  }

  addImageClick(e) {
    e.preventDefault();
    this.files = this.files.concat({
      url: 'assets/src/img/product1.png'
    });
  }

  imageClick(params) {
    console.log(params);
  }
}
